<%!

  Copyright (c) Facebook, Inc. and its affiliates.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.

%><%#program:enums%>

namespace apache { namespace thrift {

constexpr std::size_t const TEnumTraits<<% > common/namespace_cpp2%><%enum:name%>>::size;
folly::Range<<% > common/namespace_cpp2%><%enum:name%> const*> const TEnumTraits<<% > common/namespace_cpp2%><%enum:name%>>::values = <%!
  %><%#enum:empty?%><%!
    %>{};<%!
  %><%/enum:empty?%><%!
  %><%^enum:empty?%><%!
    %>folly::range(<% > common/namespace_cpp2%>_<%enum:name%>EnumDataStorage::values);<%!
  %><%/enum:empty?%>
folly::Range<folly::StringPiece const*> const TEnumTraits<<% > common/namespace_cpp2%><%enum:name%>>::names = <%!
  %><%#enum:empty?%><%!
    %>{};<%!
  %><%/enum:empty?%><%!
  %><%^enum:empty?%><%!
    %>folly::range(<% > common/namespace_cpp2%>_<%enum:name%>EnumDataStorage::names);<%!
  %><%/enum:empty?%>

char const* TEnumTraits<<% > common/namespace_cpp2%><%enum:name%>>::findName(type value) {
  using factory = <% > common/namespace_cpp2%>_<%enum:name%>_EnumMapFactory;
  static folly::Indestructible<factory::ValuesToNamesMapType> const map{
      factory::makeValuesToNamesMap()};
  auto found = map->find(value);
  return found == map->end() ? nullptr : found->second;
}

bool TEnumTraits<<% > common/namespace_cpp2%><%enum:name%>>::findValue(char const* name, type* out) {
  using factory = <% > common/namespace_cpp2%>_<%enum:name%>_EnumMapFactory;
  static folly::Indestructible<factory::NamesToValuesMapType> const map{
      factory::makeNamesToValuesMap()};
  auto found = map->find(name);
  return found == map->end() ? false : (*out = found->second, true);
}

}} // apache::thrift

<% > common/namespace_cpp2_begin%>

FOLLY_PUSH_WARNING
FOLLY_GNU_DISABLE_WARNING("-Wdeprecated-declarations")
const _<%enum:name%>_EnumMapFactory::ValuesToNamesMapType _<%enum:name%>_VALUES_TO_NAMES = _<%enum:name%>_EnumMapFactory::makeValuesToNamesMap();
const _<%enum:name%>_EnumMapFactory::NamesToValuesMapType _<%enum:name%>_NAMES_TO_VALUES = _<%enum:name%>_EnumMapFactory::makeNamesToValuesMap();
FOLLY_POP_WARNING

<% > common/namespace_cpp2_end%>

<%/program:enums%>
